package appfuse.framework.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class MapEx {
	private final Map m = new HashMap();
	private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
	private final Lock r = rwl.readLock();
	private final Lock w = rwl.writeLock();

	public Object get(Object key) {
		r.lock();
		try {
			return m.get(key);
		} finally {
			r.unlock();
		}
	}

	public Object put(Object key, Object value) {
		w.lock();
		try {
			return m.put(key, value);
		} finally {
			w.unlock();
		}
	}
	
	public Object remove(Object key){
		w.lock();
		try {
			return m.remove(key);
		} finally {
			w.unlock();
		}
	}
	
	public Set keySet(){
		r.lock();
		try{
			return m.keySet();
		} finally{
			r.unlock();
		}
	}

	public void clear() {
		w.lock();
		try {
			m.clear();
		} finally {
			w.unlock();
		}
	}

}
